package com.job.Yangmingyu.String0715;

import java.util.Arrays;

/**
 * @author com.job.Yangmingyu
 * @version 1.0
 * @since 2022-07-15 14:45:37
 */
public class Stringconstructer {
    public static void main(String[] args) {
        byte[] bytes={97,98,99,100,101,102};
        String s1=new String(bytes);//按照默认字符集Unicode来转换字节整数的码值到字符
        System.out.println(s1);

        String s2=new String(bytes, 1, 3);
        System.out.println(s2);

        char[] chars={'A','我',66,'!','=','他'};
        System.out.println(new String(chars));
        String s3=new String(chars, 3, 3);
        System.out.println(s3);

        //字符串到字节/字符数组
        String name="夏日一个雪糕";//UTF-8下 一个汉字字节用3个字节表示 2~4个
        byte[] namebytes=name.getBytes();
        System.out.println(Arrays.toString(namebytes));

        char[] chars1=name.toCharArray();
        System.out.println(Arrays.toString(chars1));

        char c=name.charAt(3);//指定下标处的字符 下标从0开始
        System.out.println(c);
        //长度，字符个数
        System.out.println(name.length());
        for (int i=0;i<=name.length();i++){
            System.out.println(i+"="+name.charAt(i));
        }
        //求字符串里的大写字符个数
        String str="public class Stringconstructer ";
        int count=0;
        for (int i=0;i<=str.length();i++){
            if (Character.isUpperCase(str.charAt(i))){//要么比较码值 65：A
                count++;
            }
        }
        System.out.println(count);
    }
}